
<?php
    const HOST = 'localhost';
    const USERNAME = 'root';
    const PASSWORD = 'root';
    const DBNAME = 'shopping';

    $conn = mysqli_connect(HOST,USERNAME,PASSWORD,DBNAME);
    // var_dump($conn);

    if($conn->connect_error){
        die("连接失败:".$conn->connect_error);
    }

$username=$_REQUEST['username'];
$couponid=$_REQUEST['couponid'];

    // 查询数据库
    mysqli_select_db($conn,"shopping");
    $sql = "select * from user_coupon where username='$username' and couponid='$couponid'";
    

    mysqli_query($conn,"set names 'utf8'");
    $result = mysqli_query($conn,$sql);


$arrnew = array();
    
    if(mysqli_num_rows($result)>0){
        // 循环遍历，拿到每一条数据
        while($row = mysqli_fetch_assoc($result)){
            
            array_push($arrnew,$row);
            //将请求结果转换为json格式，微信是能对json格式的数据进行操作
            // echo json_encode($row,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
            // echo json_encode($row);
        }
        $res = array(
            'usersnew'=> $arrnew
          );
            // echo json_encode($res,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
       
    }
    if ($res == null){
        $new="优惠券不存在";
 
   }
   else{
        $new="优惠券已存在";
   }
   echo json_encode($new);
?>
